package com.zuimei.zuimei.activities;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.zuimei.zuimei.R;
import com.zuimei.zuimei.adapters.DownloadFileListAdapter;
import com.zuimei.zuimei.base.BaseActivity;

import org.wlf.filedownloader.DownloadFileInfo;
import org.wlf.filedownloader.DownloadStatusConfiguration;
import org.wlf.filedownloader.FileDownloader;

import java.util.List;

import butterknife.Bind;
import butterknife.OnClick;

public class DownLoadManagerActivity extends BaseActivity implements DownloadFileListAdapter.OnItemSelectListener {

    @Bind(R.id.rv_content)
    RecyclerView rv_content;
    private DownloadFileListAdapter mAdapter;

    @Override
    public int getLayoutId() {
        return R.layout.activity_down_load_manager;
    }

    @Override
    protected void init() {
        Intent intent = getIntent();
        String url = intent.getStringExtra("url");
        rv_content.setLayoutManager(new LinearLayoutManager(this));
        mAdapter=new DownloadFileListAdapter(this);
        rv_content.setAdapter(mAdapter);
        mAdapter.setOnItemSelectListener(this);
        boolean isDownloadStatusConfigurationTest = false;// TEST

        if (!isDownloadStatusConfigurationTest) {
            // register to listen all
            FileDownloader.registerDownloadStatusListener(mAdapter);
        } else {
            // register to only listen special url
            DownloadStatusConfiguration.Builder builder = new DownloadStatusConfiguration.Builder();
            //builder.addListenUrl("http://182.254.149.157/ftp/image/shop/product/Kids Addition & Subtraction 1.0.apk");
            FileDownloader.registerDownloadStatusListener(mAdapter, builder.build());
        }
        FileDownloader.start(url);
    }

    @OnClick({R.id.tv_back})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_back:
                finish();
                break;
        }
    }

    @Override
    public void onSelected(List<DownloadFileInfo> selectDownloadFileInfos) {

    }

    @Override
    public void onNoneSelect() {

    }
}
